package com.zzl.bonds.ticket.constant.type;

import com.zzl.bonds.ticket.dto.KeyValue;

import java.util.ArrayList;
import java.util.List;

/**
 * 额度范围，1 集团授信 2 独立授信
 *
 * @author : gull
 * @date : 2022/2/17 10:22
 */
public enum CreditTypeEnum {


    /**
     * 开立授信
     */
    ALL(0, "全部", "凭证开立额度"),
    GROUP(1, "集团授信", "凭证开立额度"),

    /**
     * 融资授信
     */
    INDEPENDENCE(2, "独立授信", "凭证开立额度"),
    OPEN_CREDIT(3, "开立授信", ""),
    FINANCE_CREDIT(4, "融资授信", ""),


    ;

    private Integer code;
    private String value;
    private String description;

    CreditTypeEnum(Integer code, String value, String description) {
        this.code = code;
        this.value = value;
        this.description = description;
    }

    public static String getValue(Integer code) {
        for (CreditTypeEnum statusEnum : CreditTypeEnum.values()) {
            if (statusEnum.code.equals(code)) {
                return statusEnum.value;
            }
        }
        return "";
    }

    /**
     * 额度管理的授信范围
     *
     * @return 集合
     */
    public static List<KeyValue> getKvList(String type) {
        List<KeyValue> keyValues = new ArrayList<>();
        for (CreditTypeEnum creditTypeEnum : CreditTypeEnum.values()) {
            if (creditTypeEnum.description.equals(type)) {
                KeyValue kv = new KeyValue();
                kv.setKey(creditTypeEnum.code);
                kv.setValue(creditTypeEnum.value);
                keyValues.add(kv);
            }
        }
        return keyValues;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public String getDescription() {
        return description;
    }
}
